﻿Imports System.Windows.Forms

Public Class frmToolbar

    Private _ToolStrip As ToolStrip

    Public Sub New(ByVal ToolStrip As ToolStrip)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        _ToolStrip = ToolStrip

#If Project = "WRDBLIB" Then
        lnkDefaults.Visible = True
#End If
    End Sub

    ''' <summary>
    ''' Shared method to load toolbar settings from registry
    ''' </summary>
    ''' <param name="_ToolStrip">Form's toolstrip control</param>
    Public Shared Sub GetToolbarSettings(ByVal _ToolStrip As ToolStrip)
        Dim Section As String = _ToolStrip.Parent.Name & "_Toolstrip"
        Dim ShowText As Boolean = GetSetting(REGAPP, Section, "ShowText", True)
        For Each tb As ToolStripItem In _ToolStrip.Items
            tb.Visible = GetSetting(REGAPP, Section, tb.Tag, tb.Visible)
            tb.DisplayStyle = IIf(ShowText, ToolStripItemDisplayStyle.ImageAndText, ToolStripItemDisplayStyle.Image)
            If TypeOf (tb) Is ToolStripButton Then CType(tb, ToolStripButton).TextImageRelation = TextImageRelation.ImageAboveText
        Next
    End Sub

    Private Sub SaveSettings()
        Dim Section As String = _ToolStrip.Parent.Name & "_Toolstrip"
        SaveSetting(REGAPP, Section, "ShowText", _ToolStrip.Items(0).DisplayStyle = ToolStripItemDisplayStyle.ImageAndText)
        For Each tb As ToolStripItem In _ToolStrip.Items
            SaveSetting(REGAPP, Section, tb.Tag, tb.Visible)
        Next
    End Sub

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        For i As Integer = 0 To lstToolbarButtons.Items.Count - 1
            Dim tb As ToolStripItem = _ToolStrip.Items(i)
            tb.DisplayStyle = IIf(chkTextVisible.Checked, ToolStripItemDisplayStyle.ImageAndText, ToolStripItemDisplayStyle.Image)
            If TypeOf (tb) Is ToolStripButton Then CType(tb, ToolStripButton).TextImageRelation = TextImageRelation.ImageAboveText
            tb.Visible = lstToolbarButtons.GetItemChecked(i)
        Next
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        SaveSettings()
        Me.Close()
    End Sub

    Private Sub frmToolbar_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For Each tb As ToolStripItem In _ToolStrip.Items
            lstToolbarButtons.Items.Add(tb.Tag, tb.Visible)
        Next
        chkTextVisible.Checked = (_ToolStrip.Items(0).DisplayStyle = ToolStripItemDisplayStyle.ImageAndText)
    End Sub

    Private Sub lstToolbarButtons_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles lstToolbarButtons.ItemCheck
        Dim tb As ToolStripItem = _ToolStrip.Items(e.Index)
        tb.Visible = e.NewValue = CheckState.Checked
    End Sub

    Private Sub chkTextVisible_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTextVisible.CheckedChanged
        For i As Integer = 0 To lstToolbarButtons.Items.Count - 1
            Dim tb As ToolStripItem = _ToolStrip.Items(i)
            tb.DisplayStyle = IIf(chkTextVisible.Checked, ToolStripItemDisplayStyle.ImageAndText, ToolStripItemDisplayStyle.Image)
            If TypeOf (tb) Is ToolStripButton Then CType(tb, ToolStripButton).TextImageRelation = TextImageRelation.ImageAboveText
            tb.Visible = lstToolbarButtons.GetItemChecked(i)
        Next
    End Sub

    Private Sub lnkAllVisible_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkAllVisible.LinkClicked
        For i As Integer = 0 To lstToolbarButtons.Items.Count - 1
            lstToolbarButtons.SetItemChecked(i, True)
        Next
    End Sub

    Private Sub lnkDefaults_LinkClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkDefaults.LinkClicked
        For i As Integer = 0 To lstToolbarButtons.Items.Count - 1
            lstToolbarButtons.SetItemChecked(i, False)
        Next
#If Project = "WRDBLIB" Then
        With MainForm
            .tbOpenProject.Visible = True
            .tbPrefs.Visible = True
            .tbExplore.Visible = True
            .tbSepExplore.Visible = True
            .tbLogin.Visible = True
            .tbNew.Visible = True
            .tbOpenWorking.Visible = True
            .tbOpenMaster.Visible = True
            .tbOpenSupport.Visible = True
            .tbSepOpenSupport.Visible = True
            .tbEditDataEntry.Visible = True
            .tbDeleteSelected.Visible = True
            .tbImportFile.Visible = True
            .tbDownload.Visible = True
            .tbSelectAll.Visible = True
            .tbSelectRng.Visible = True
            .tbSelectAdv.Visible = True
            .tbSelectSQL.Visible = True
            .tbSelectShow.Visible = True
            .tbSepSelect.Visible = True
            .tbRptSP.Visible = True
            .tbRptS.Visible = True
            .tbRptP.Visible = True
            .tbSepRpt.Visible = True
            .tbGraphTS.Visible = True
            .tbGraphLong.Visible = True
            .tbGIS.Visible = True
            .tbExport.Visible = True
            .tbSave.Visible = True
            .tbSepOutput.Visible = True
            .tbHelp.Visible = True
        End With
        For i As Integer = 0 To lstToolbarButtons.Items.Count - 1
            If _ToolStrip.Items(i).Visible Then lstToolbarButtons.SetItemChecked(i, True)
        Next
#End If
    End Sub
End Class
